package algorithm.ListNode;

/**
 * @Author: 李浩然
 * @Date: 2020/12/29 10:37 上午
 */
public class reverseNode {
    public static Node reverseNode1(Node head) {
        if (head == null || head.next == null) {
            return head;
        }
        Node next = head.next;
        head.next = null;
        Node newHead = reverseNode1(next);
        next.next = head;
        return newHead;
    }

    public static Node reverseNode2(Node head) {
        if (head == null || head.next == null) {
            return head;
        }
        Node newList = new Node(-1);
        while (head != null) {
            Node next = head.next;
            head.next = newList.next;
            newList.next = head;
            head = next;
        }
        return newList.next;
    }
}
